/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.techshop.controller;

import com.techshop.model.Manufacturer;
import com.techshop.service.ManufacturerService;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Hai-PC
 */
@ManagedBean(name="manufacturerController")
@SessionScoped
public class ManufacturerController extends AbstractController{
    
    Manufacturer selectedManufacturer = new Manufacturer();
    
    List<Manufacturer> manufacturerList;
    
    @ManagedProperty(value="#{manufacturerService}")
    ManufacturerService manufacturerService;
    
    public void insert()
    {
        
        if(getManufacturerService().insert(selectedManufacturer))
        {
            addInfoMessage("Thêm nhà sản xuất thành công");
        }
        else
        {
            addErrorMessage("Thêm nhà sản xuất không thành công");
        }
    }
    
    public void update()
    {
        if (getManufacturerService().update(selectedManufacturer))
        {
            addInfoMessage("Cập nhật nhà sản xuất thành công");
        }
        else
        {
            addErrorMessage("Cập nhật nhà sản xuất không thành công");
        }
    }
    
    public void delete()
    {
        if (getManufacturerService().delete(selectedManufacturer))
        {
            addInfoMessage("Xóa nhà sản xuất thành công");
        }
        else
        {
            addErrorMessage("Xóa nhà sản xuất không thành công");
        }
    }
    
    public void resetSelectedManufacturer()
    {
        selectedManufacturer = new Manufacturer();
    }
    
    /**
     * @return the manufacturerList
     */
    public List<Manufacturer> getManufacturerList()
    {
        return getManufacturerService().findAll();
    }
    
    /**
     * @param manufacturerList the manufacturerList to set
     */
    public void setManufacturerList(List<Manufacturer> manufacturerList)
    {
        this.manufacturerList = manufacturerList;
    }

    /**
     * @return the manufacturerService
     */
    public ManufacturerService getManufacturerService()
    {
        return manufacturerService;
    }

    /**
     * @param manufacturerService the manufacturerService to set
     */
    public void setManufacturerService(ManufacturerService manufacturerService)
    {
        this.manufacturerService = manufacturerService;
    }

    /**
     * @return the selectedManufacturer
     */
    public Manufacturer getSelectedManufacturer()
    {
        return selectedManufacturer;
    }

    /**
     * @param selectedManufacturer the selectedManufacturer to set
     */
    public void setSelectedManufacturer(Manufacturer selectedManufacturer)
    {
        this.selectedManufacturer = selectedManufacturer;
    }
}